<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\model\user;

use think\Model;

/**
 * 用户头衔绑定 模型
 * @package app\user_center\model
 */
class UcMemberTitlecertification extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_member_titlecertification';
	
	//认证状态
    public function getStatusAttr($value){
        $status = [0=>'申请中', 1=>'申请通过', 2=>'拒绝申请'];
        return $status[$value];
    }
	
	//认证方式 1企业 2个人
    public function getCertifiTypeAttr($value){
        $status = [1=>'企业', 2=>'个人'];
        return $status[$value];
    }
	
	/**
     * 插入认证记录
	 * @param  int 	  	$uid  	用户ID
     * @param  int 		$type   1企业 2个人
     * @param  int 		$classification_id   		行业id
     * @param  string	$business_license_url		营业执照url 
     * @param  string	$certification_letter_url	认证公函url 
     * @param  string	$other_url1-5				其他资质
     * @param  string	$name						申请者名
     * @param  string	$certification_information	认证信息
     * @param  string	$operator_name				管理员名
     * @param  int		$operator_mobile			手机号码
     * @param  int		$operator_code				验证码
     * @param  string	$operator_email				管理员邮箱
     * @param  string	$invoice_email				发票接收邮箱
     * @param  string	$yaoqing_code				邀请码
     * @param  string	$opening_bank				开户行
     * @param  string	$bank_code					银行卡号
     * @param  string	$address					企业地址
     * @param  string	$tel_num					企业电话
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
	public function addData($params){
		$this -> uid	    					= $params['uid'];
		$this -> certifi_type   				= $params['certifi_type'];
		$this -> classification_id  			= $params['classification_id'];
		$this -> business_license_url   		= $params['business_license_url'];
		$this -> certification_letter_url   	= $params['certification_letter_url'];
		$this -> other_url1   					= $params['other_url1'];
		$this -> other_url2   					= $params['other_url2'];
		$this -> other_url3   					= $params['other_url3'];
		$this -> other_url4   					= $params['other_url4'];
		$this -> other_url5   					= $params['other_url5'];
		$this -> certifi_name   				= $params['certifi_name'];
		$this -> certification_information   	= $params['certification_information'];
		$this -> operator_name   				= $params['operator_name'];
		$this -> operator_mobile   				= $params['operator_mobile'];
		$this -> operator_email   				= $params['operator_email'];
		$this -> invoice_email   				= $params['invoice_email'];
		$this -> yaoqing_code   				= $params['yaoqing_code'];
		$this -> opening_bank   				= $params['opening_bank'];
		$this -> bank_code   					= $params['bank_code'];
		$this -> address   						= $params['address'];
		$this -> tel_num   						= $params['tel_num'];
		$this -> id_card_side   				= $params['id_card_side'];
		$this -> id_card_positive   			= $params['id_card_positive'];
		$this -> status   						= 0;
		$res = $this -> isUpdate(false) -> save();//添加  thinkphp主键bug
		if($res){
			return array_out(200, 'success');
		}else{
			return array_out(-1001, 'error');
		}
	}
	
	/**
     * 修改认证信息
     * @param  int 	  	$uid  	用户ID
     * @param  int 		$type   1企业 2个人
     * @param  int 		$classification_id   		行业id
     * @param  string	$business_license_url		营业执照url 
     * @param  string	$certification_letter_url	认证公函url 
     * @param  string	$other_url1-5				其他资质
     * @param  string	$name						申请者名
     * @param  string	$certification_information	认证信息
     * @param  string	$operator_name				管理员名
     * @param  int		$operator_mobile			手机号码
     * @param  int		$operator_code				验证码
     * @param  string	$operator_email				管理员邮箱
     * @param  string	$invoice_email				发票接收邮箱
     * @param  string	$yaoqing_code				邀请码
     * @param  string	$opening_bank				开户行
     * @param  string	$bank_code					银行卡号
     * @param  string	$address					企业地址
     * @param  string	$tel_num					企业电话
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
	public function editData($params){
		
		$map = [];
		$map['certifi_type']   				= $params['certifi_type'];
		$map['classification_id']  			= $params['classification_id'];
		$map['business_license_url']   		= $params['business_license_url'];
		$map['certification_letter_url']   	= $params['certification_letter_url'];
		$map['other_url1']  				= $params['other_url1'];
		$map['other_url2']   				= $params['other_url2'];
		$map['other_url3']   				= $params['other_url3'];
		$map['other_url4']   				= $params['other_url4'];
		$map['other_url5']   				= $params['other_url5'];
		$map['certifi_name']   				= $params['certifi_name'];
		$map['certification_information']   = $params['certification_information'];
		$map['operator_name']   			= $params['operator_name'];
		$map['operator_mobile']   			= $params['operator_mobile'];
		$map['operator_email']   			= $params['operator_email'];
		$map['invoice_email']   			= $params['invoice_email'];
		$map['yaoqing_code']   				= $params['yaoqing_code'];
		$map['opening_bank']   				= $params['opening_bank'];
		$map['bank_code']   				= $params['bank_code'];
		$map['address']   					= $params['address'];
		$map['tel_num']   					= $params['tel_num'];
		$map['id_card_side']    			= $params['id_card_side'];
		$map['id_card_positive']    		= $params['id_card_positive'];
		$map['status']   					= 0;
		
		$res = self::where('uid' ,'=' , $params['uid']) ->update($map);
		if($res){
			return array_out(200, 'success');
		}else{
			return array_out(-1001, 'error');
		}
	}
	
	/**
     * 更新认证状态
     * @param int $id
     * @param int $status 		状态 0 申请中 1通过 2拒绝
     * @param string $reason 	拒绝理由
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
	public function useData($list){
		$res = $this -> saveAll($list);
        if($res){
            return array_out(200, 'success');
        }else{
             return array_out(-1001, 'error');
        }
    }
	
	/**
     * 用户统计 关联载入（一对一）
     */
    public function getUcMember(){
        return $this -> hasOne('app\user_center\model\user\Member','uid', 'uid');
    }
	
	/**
     * 行业关联 关联载入（一对一）
     */
    public function getBaseIndustryClassification(){
        return $this -> hasOne('app\user_center\model\user\BaseIndustryClassification','id', 'classification_id');
    }
}
